<template>
	<view>
		<f-navbar title="修改手机号"></f-navbar>
		<view class="modify-phone">
			<view class="form">
				<view class="form-item">
					<u-input color="#000000" fontSize="28rpx" placeholderStyle="color:#BBBBBB;font-size:28rpx;"
						placeholder="请输入新手机号" border="none" v-model="form.phone"></u-input>
				</view>
				<view class="form-item">
					<u-input color="#000000" fontSize="28rpx" placeholderStyle="color:#BBBBBB;font-size:28rpx;"
						placeholder="请输入短信验证码" border="none" v-model="form.code">
						<template slot="suffix">
							<u-code ref="uCode" @change="codeChange" keep-running startText="发送验证码" changeText="XS" endText="重新发送"
								unique-key="changePhone"></u-code>
							<view class="codeText" @tap="getCode">{{tips}}</view>
						</template>
					</u-input>
				</view>
			</view>
			<view class="login-btn">
				<u-button color="linear-gradient(83deg, #48B453 0%, #2C9F79 100%)"
					:customStyle="{width:'610rpx',height:'80rpx',fontSize:'32rpx',borderRadius:'50rpx',fontWeight:'bold'}"
					@click="submitForm">确认修改
				</u-button>
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				tips: "",
				form: {
					phone: null,
					code: null
				}
			};
		},
		methods: {
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: "正在获取验证码",
					});
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast("验证码已发送");
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					uni.$u.toast("倒计时结束后再发送");
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	.modify-phone {
		.form {
			margin-top: 30rpx;
			padding: 0 30rpx;
			background: #fff;
		}

		.form-item {
			padding: 30rpx 0;
			border-bottom: 1rpx solid #EFEFEF;
			display: flex;
			align-items: center;
			&:last-child {
				border: none;
			}

			.codeText {
				font-size: 28rpx;
				color: #138e57;
			}
		}

		.login-btn {
			margin-top: 80rpx;
		}

	}
</style>